<?php

class Xzsdsplus_Costpriceplus_Block_Groups_Grid extends Mage_Adminhtml_Block_Widget_Grid {
    public function __construct()
    {
        parent::__construct();
        $this->setId('groupsGrid');
        $this->setDefaultSort('entity_id');
        $this->setDefaultDir('ASC');
        $this->setSaveParametersInSession(true);
    }
    
    protected function _getStore()
    {
        $storeId = (int) $this->getRequest()->getParam('store', 0);
        return Mage::app()->getStore($storeId);
    }
    
    protected function _prepareCollection()
    {
        $collection = Mage::getModel('costpriceplus/groups')->getCollection();

        $this->setCollection($collection);
        return parent::_prepareCollection();
    }
    
    protected function _prepareColumns()
    {
        $this->addColumn('entity_id', array(
            'header'	=> Mage::helper('costpriceplus')->__('ID'),
            'index'		=> 'entity_id',
            'align'     => 'right',
            'width'     => '50px',
        ));
        
        $this->addColumn('group_name', array(
            'header'	=> Mage::helper('costpriceplus')->__('Group Title'),
            'index'		=> 'group_name',
        ));
        
        $this->addColumn('cpp_type', array(
            'header'	=> Mage::helper('costpriceplus')->__('Type'),
            'index'		=> 'cpp_type',
            'align'     => 'left',
            'width'     => '80px',
            'type'      => 'options',
            'options'   => array(
                  1 => Mage::helper('costpriceplus')->__('Fixed'),
                  2 => Mage::helper('costpriceplus')->__('Percent'),
              ),
        ));
        
        $store = $this->_getStore();
        $this->addColumn('amount', array(
            'header'		=> Mage::helper('costpriceplus')->__('Amount'),
            'index'			=> 'amount',
            'renderer'		=> 'costpriceplus/groups_column_renderer_amount',
            'currency_code'	=> $store->getBaseCurrency()->getCode(),
        ));
        
        $this->addColumn('is_active', array(
            'header'	=> Mage::helper('costpriceplus')->__('Status'),
            'index'		=> 'is_active',
            'align'     => 'left',
            'width'     => '80px',
            'type'      => 'options',
            'options'   => array(
                  1 => Mage::helper('costpriceplus')->__('Active'),
                  0 => Mage::helper('costpriceplus')->__('Inactive'),
              ),
        ));
        
        $this->addColumn('action',
            array(
                'header'    =>  Mage::helper('costpriceplus')->__('Action'),
                'width'     => '100',
                'type'      => 'action',
                'getter'    => 'getId',
                'actions'   => array(
                    array(
                        'caption'   => Mage::helper('costpriceplus')->__('Edit'),
                        'url'       => array('base'=> '*/*/edit'),
                        'field'     => 'id'
                    )
                ),
                'filter'    => false,
                'sortable'  => false,
                'index'     => 'stores',
                'is_system' => true,
        ));
        
        return parent::_prepareColumns();
    }
    
    public function getRowUrl($row)
    {
        return $this->getUrl('*/*/edit', array('id' => $row->getId()));
    }
}
